package com.chen.Dome5TCP2;

import java.io.DataInputStream;
import java.io.InputStream;
import java.net.Socket;

public class ServerReader extends Thread {
    private Socket s;

    public ServerReader(Socket s) {// 构造方法// 把参数保存起来
        this.s = s;
    }

    @Override
    public void run() {
        try {
            InputStream is = s.getInputStream();
            //4.把字节流包装成缓冲字符流，提高效率
            DataInputStream dis = new DataInputStream(is);
            while (true) {
                String msg = dis.readUTF();
                System.out.println("客户端发送的数据是：" + "---" + msg);
                //5.获取客户端的IP和端口
                System.out.println("客户端的IP地址是：" + s.getInetAddress().getHostAddress());
                System.out.println("客户端的端口号是：" + s.getPort());
            }
            } catch(Exception e){
            System.out.println(s.getInetAddress().getHostAddress()+"客户下线了");
            }

        }
    }

